package com.viettel.rmsmobile;

import com.viettel.menu.PlanetFragment;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class ViewJobDetailActivity extends Fragment {

	TextView positionName;
	TextView organizationName;
	TextView locationName;
	TextView jobDescription;
	TextView jobRequire;
	TextView globalRequire;
	TextView endDate;
	TextView quantity;
	TextView otherRequire;
	TextView address;
	TextView recruitmentName;
	TextView type;
	TextView interest;
	Button btnApply;
	Button btnSaveJob;
	private Long recruitmentAnouncementId;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater
				.inflate(R.layout.view_job_detail, container, false);
		positionName = (TextView) view.findViewById(R.id.positionName);
		organizationName = (TextView) view.findViewById(R.id.organizationName);
		locationName = (TextView) view.findViewById(R.id.locationName);
		jobDescription = (TextView) view.findViewById(R.id.jobDescription);
		jobRequire = (TextView) view.findViewById(R.id.jobRequire);
		globalRequire = (TextView) view.findViewById(R.id.globalRequire);
		// endDate= (TextView) findViewById(R.id.endDate);
		// quantity= (TextView) findViewById(R.id.quantity);
		otherRequire = (TextView) view.findViewById(R.id.otherRequire);
		otherRequire = (TextView) view.findViewById(R.id.otherRequire);
		// address= (TextView) findViewById(R.id.address);
		// recruitmentName= (TextView) findViewById(R.id.recruitmentName);
		// type= (TextView) findViewById(R.id.type);
		interest = (TextView) view.findViewById(R.id.interest);

		positionName.setText(Html.fromHtml(getArguments().getString(
				"positionName")));
		organizationName.setText(Html.fromHtml(getArguments().getString(
				"organizationName")));
		locationName.setText(Html.fromHtml(getArguments().getString(
				"locationName")));
		jobDescription.setText(Html.fromHtml(getArguments().getString(
				"jobDescription")));
		jobRequire.setText(Html
				.fromHtml(getArguments().getString("jobRequire")));
		globalRequire.setText(Html.fromHtml(getArguments().getString(
				"globalRequire")));
		// endDate.setText(Html.fromHtml(getArguments().getString("endDate")));
		// quantity.setText(getArguments().getString("quantity")));
		otherRequire.setText(Html.fromHtml(getArguments().getString(
				"otherRequire")));
		// address.setText(Html.fromHtml(getArguments().getString("address")));
		// recruitmentName.setText(Html.fromHtml(getArguments().getString("recruitmentName")));
		// type.setText(Html.fromHtml(getArguments().getString("type")));
		interest.setText(Html.fromHtml(getArguments().getString("interest")));
		recruitmentAnouncementId = getArguments().getLong(
				"recruitmentAnouncementId", -1L);

		btnApply = (Button) view.findViewById(R.id.btnApply);
		btnSaveJob = (Button) view.findViewById(R.id.btnSaveJob);
		btnSaveJob.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				applyJob(v);
			}
		});
		
		btnApply.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				applyJob(v);
			}
		});
		return view;
	}

	/**
	 * Nop don
	 * 
	 * @param v
	 */
	public void applyJob(View v) {
		if (MainActivity.portalUserId == null || MainActivity.portalUser == null || MainActivity.portalUser.getEmail() == null) {
			Fragment fragment=new UserLoginActivity();
			FragmentManager fragmentManager = getFragmentManager();
			fragmentManager.beginTransaction()
					.replace(R.id.content_frame, fragment).commit();
		} else {
			Fragment fragment=new ApplyJobActivity();
			Bundle args = new Bundle();
			args.putLong("recruitmentAnouncementId", recruitmentAnouncementId);
			fragment.setArguments(args);
			FragmentManager fragmentManager = getFragmentManager();
			fragmentManager.beginTransaction()
					.replace(R.id.content_frame, fragment).commit();
		}
	}
}
